/**
 * 饭店仿真
 *
 * @author fireway
 * @since 2019年 03月 20日 星期三 07:10:31 CST
 */
package concurrency;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class RestaurantWithQueues {
    public static void main(String[] args) {
        ExecutorService exec = Executors.newCachedThreadPool();
        Restaurant restaurant = new Restaurant(exec, 5, 2);
        exec.execute(restaurant);

        if(args.length > 0) {
            try {
                TimeUnit.SECONDS.sleep(new Integer(args[0]));
            } catch (NumberFormatException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        } else {
            System.out.println("Press 'Enter' to quit");
            try {
                System.in.read();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        exec.shutdownNow();
    }
}
